Skip to content

Conversation

@BrennanConroy
Copy link
Member

Moving to HostBuilder and thus TestServer in the DI container, instead of explicitly creating it, has caused an ODE to appear in this test because we weren't closing the connection but were closing the host.

Should be fixed by closing the connection before closing the host.

Copilot AI review requested due to automatic review settings August 15, 2025 17:05
@github-actions github-actions bot added the area-signalr Includes: SignalR clients and servers label Aug 15, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes an ObjectDisposedException (ODE) that was occurring in SignalR TestServer tests by ensuring proper resource cleanup. The issue arose when moving to HostBuilder and TestServer in the DI container, where connections weren't being properly disposed before the host was closed.

  • Updates connection disposal to use await using pattern for automatic async disposal
  • Ensures connections are properly closed before host disposal to prevent ObjectDisposedException

connectionBuilder.Services.AddLogging();
connectionBuilder.Services.AddSingleton(LoggerFactory);
var connection = connectionBuilder.Build();
await using var connection = connectionBuilder.Build();
Copy link

Copilot AI Aug 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using await using for connection disposal is correct, but ensure that the connection is explicitly stopped before disposal to prevent potential race conditions. Consider calling await connection.StopAsync() before the connection goes out of scope.

Copilot uses AI. Check for mistakes.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DisposeAsync does the same thing as StopAsync for the HubConnection.

connectionBuilder.Services.AddLogging();
connectionBuilder.Services.AddSingleton(LoggerFactory);
var connection = connectionBuilder.Build();
await using var connection = connectionBuilder.Build();
Copy link

Copilot AI Aug 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using await using for connection disposal is correct, but ensure that the connection is explicitly stopped before disposal to prevent potential race conditions. Consider calling await connection.StopAsync() before the connection goes out of scope.

Copilot uses AI. Check for mistakes.
@BrennanConroy BrennanConroy merged commit 1abbddc into main Aug 15, 2025
30 checks passed
@BrennanConroy BrennanConroy deleted the BrennanConroy-patch-3 branch August 15, 2025 20:47
@dotnet-policy-service dotnet-policy-service bot added this to the 10.0-rc1 milestone Aug 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-signalr Includes: SignalR clients and servers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants